import { Space, Tag } from "antd";
import { CalcSubtitleProps } from "./data";
import { forwardRef, useState } from "react";

const CalcSubtitle: React.FC<CalcSubtitleProps> = (props, uploadRef) => {
  // const [props.checkedKeys, setprops.checkedKeys] = useState<React.Key[]>([]);
  const driveTypeMap = new Map([
    [1, 'V90'],
    [2, 'S210'],
  ]);

  const encoderMap = new Map([
    [0, '单圈绝对编码器'],
    [1, '多圈绝对编码器'],
    [2, '增量式编码器'],
  ]);

  const brakeMap = new Map([
    [0, '不带抱闸'],
    [1, '带抱闸'],
  ]);

  const loadTypeMap = new Map([
    [1, '水平'],
    [2, '旋转'],
    [3, '垂直'],
    [4, '斜坡'],
    [5, '其它'],
  ]);

  const mechanicalStructureMap = new Map([
    [1, '丝杠'],
    [2, '齿轮齿条'],
    [3, '皮带轮'],
    [4, '圆盘'],
    [5, '辊式带'],
    [6, '链条'],
    [7, '其它'],
  ]);

  const controlModeMap = new Map([
    [1, 'TO'],
    [2, 'Epos'],
    [3, 'Speed'],
  ]);

  const commTelegramMap = new Map([
    [105, '105'],
    [111, '111'],
    [102, '102'],
    [3, '3'],
    [1, '1'],
  ]);

  const additionalTelegramMap = new Map([
    [999, 'None'],
    [750, '750'],
  ]);

  const motorRotationMap = new Map([
    [0, '正向'],
    [1, '反向'],
  ]);

  const originalMap = new Map([
    [0, '来自设备管理'],
    [1, '其他'],
  ]);

  const diMap = new Map([
    [0, 'NA'],
    [2, 'RESET'],
    [3, 'CWL'],
    [4, 'CCWL'],
    [11, 'TLIM'],
    [20, 'SLIM'],
    [24, 'REF'],
    [29, 'EMGS'],
  ]);

  const doMap = new Map([
    [1, 'RDY'],
    [2, 'FAULT'],
    [3, 'INP'],
    [4, 'ZSP'],
    [6, 'TLR'],
    [8, 'MBR'],
    [9, 'OLL'],
    [12, 'REFOK'],
    [14, 'RDY_ON'],
    [15, 'STO'],
    [16, 'PZD1'],
    [17, 'PZD2'],
  ]);

  const modualActiveMap = new Map([
    [1, 'Yes'],
    [0, 'No'],
  ]);

  const pzdMap = new Map([
    [0, '无功能'],
    [1, '实际扭矩'],
    [2, '实际绝对电流'],
    [3, 'DI状态'],
  ]);

  return (
    <div>
      <Space size={[0,8]} wrap>
        <Tag 
          color="blue"
          hidden={!props.checkedKeys.some(checked => checked == 'lib0')}
        > 
          {props.row.shaftName} 
        </Tag>
        <Tag color="purple"> {driveTypeMap.get(props.row.driveType)} </Tag>
        <Tag color="geekblue"> {props.row.motorOrderNum} </Tag>
      
        <Tag 
          color="cyan" 
          hidden={!props.checkedKeys.some(checked => checked == 'lib4-0')}
        > 
          {'负载类型: ' + loadTypeMap.get(props.row.loadType)} 
        </Tag>
        <Tag 
          color="cyan" 
          hidden={!props.checkedKeys.some(checked => checked == 'lib4-1')}
        > 
          {'机械结构: ' + mechanicalStructureMap.get(props.row.mechanicalStructure)} 
        </Tag>
        <Tag 
          color="cyan" 
          hidden={!props.checkedKeys.some(checked => checked == 'lib4-2')}
        > 
          {'控制报文: ' + commTelegramMap.get(props.row.commTelegram)} 
        </Tag>
        <Tag 
          color="cyan" 
          hidden={!props.checkedKeys.some(checked => checked == 'lib4-3')}
        > 
          {'附加报文: ' + additionalTelegramMap.get(props.row.additionalTelegram)} 
        </Tag>
        <Tag 
          color="cyan" 
          hidden={!props.checkedKeys.some(checked => checked == 'lib4-4')}
        > 
          {'控制模式: ' + controlModeMap.get(props.row.controlMode)} 
        </Tag>
        <Tag 
          color="green" 
          hidden={!props.checkedKeys.some(checked => checked == 'lib4-5')}
        > 
          {'电机旋转方向: ' + motorRotationMap.get(props.row.motorRotation)} 
        </Tag>
        <Tag 
          color="green" 
          hidden={!props.checkedKeys.some(checked => checked == 'lib4-6')}
        > 
          {'P1082: ' + props.row.velocityMax} 
        </Tag>
        <Tag 
          color="green" 
          hidden={!props.checkedKeys.some(checked => checked == 'lib4-7')}
        > 
          {'P2000: ' + props.row.refSpeed} 
        </Tag>
        <Tag 
          color="green" 
          hidden={!props.checkedKeys.some(checked => checked == 'lib4-8')}
        > 
          {'P2002: ' + props.row.refCurrent} 
        </Tag>
        <Tag 
          color="green" 
          hidden={!props.checkedKeys.some(checked => checked == 'lib4-9')}
        > 
          {'P2003: ' + props.row.refTorque} 
        </Tag>
        <Tag 
          color="green" 
          hidden={!props.checkedKeys.some(checked => checked == 'lib4-10-0')}
        > 
          {'DI1: ' + diMap.get(props.row.di1Epos)} 
        </Tag>
        <Tag 
          color="green" 
          hidden={!props.checkedKeys.some(checked => checked == 'lib4-10-1')}
        > 
          {'DI2: ' + diMap.get(props.row.di2Epos)} 
        </Tag>
        <Tag 
          color="green" 
          hidden={!props.checkedKeys.some(checked => checked == 'lib4-10-2')}
        > 
          {'DI3: ' + diMap.get(props.row.di3Epos)} 
        </Tag>
        <Tag 
          color="green" 
          hidden={!props.checkedKeys.some(checked => checked == 'lib4-10-3')}
        > 
          {'DI4: ' + diMap.get(props.row.di4Epos)} 
        </Tag>
        <Tag 
          color="green" 
          hidden={!props.checkedKeys.some(checked => checked == 'lib4-11-0')}
        > 
          {'DO1: ' + doMap.get(props.row.do1Epos)} 
        </Tag>
        <Tag 
          color="green" 
          hidden={!props.checkedKeys.some(checked => checked == 'lib4-11-1')}
        > 
          {'DO2: ' + doMap.get(props.row.do2Epos)} 
        </Tag>
        <Tag 
          color="green" 
          hidden={!props.checkedKeys.some(checked => checked == 'lib4-12-0')}
        > 
          {'P29050[0]: ' + props.row.getTorqueLimUpper} 
        </Tag>
        <Tag 
          color="green" 
          hidden={!props.checkedKeys.some(checked => checked == 'lib4-12-1')}
        > 
          {'P29051[0]: ' + props.row.getTorqueLimLower} 
        </Tag>
        <Tag 
          color="green" 
          hidden={!props.checkedKeys.some(checked => checked == 'lib4-13-0')}
        > 
          {'P1215: ' + brakeMap.get(props.row.brake)} 
        </Tag>
        <Tag 
          color="green" 
          hidden={!props.checkedKeys.some(checked => checked == 'lib4-13-1')}
        > 
          {'P1216: ' + props.row.tbrakeOpen} 
        </Tag>
        <Tag 
          color="green" 
          hidden={!props.checkedKeys.some(checked => checked == 'lib4-13-2')}
        > 
          {'P1217: ' + props.row.tbrakeClose} 
        </Tag>

        <Tag 
          color="#2db7f5" 
          hidden={!props.checkedKeys.some(checked => checked == 'lib5-00')}
        > 
          {'动态系数: ' + props.row.dynamicCoeff} 
        </Tag>
        <Tag 
          color="lime" 
          hidden={!props.checkedKeys.some(checked => checked == 'lib5-0-0')}
        > 
          {'P29248: ' + props.row.gearRationLoad} 
        </Tag>
        <Tag 
          color="lime" 
          hidden={!props.checkedKeys.some(checked => checked == 'lib5-0-1')}
        > 
          {'P29249: ' + props.row.gearRationMotor} 
        </Tag>
        <Tag 
          color="lime" 
          hidden={!props.checkedKeys.some(checked => checked == 'lib5-0-2')}
        > 
          {'10mm对应的LU: ' + props.row.positionAccuracy} 
        </Tag>
        <Tag 
          color="lime" 
          hidden={!props.checkedKeys.some(checked => checked == 'lib5-0-3')}
        > 
          {'P29247: ' + props.row.luLoopEpos} 
        </Tag>
        <Tag 
          color="lime" 
          hidden={!props.checkedKeys.some(checked => checked == 'lib5-0-4')}
        > 
          {'P29110: ' + props.row.kprEpos} 
        </Tag>
        <Tag 
          color="lime" 
          hidden={!props.checkedKeys.some(checked => checked == 'lib5-0-5')}
        > 
          {'P2533: ' + props.row.posFilterEpos} 
        </Tag>
        <Tag 
          color="lime" 
          hidden={!props.checkedKeys.some(checked => checked == 'lib5-0-6')}
        > 
          {'P29111: ' + props.row.coeffVelEpos} 
        </Tag>
        <Tag 
          color="lime" 
          hidden={!props.checkedKeys.some(checked => checked == 'lib5-0-7')}
        > 
          {'P2571: ' + 6 * props.row.vmaxEpos * props.row.positionAccuracy} 
        </Tag>
        <Tag 
          color="lime" 
          hidden={!props.checkedKeys.some(checked => checked == 'lib5-0-8')}
        > 
          {'P2572: ' + props.row.accmaxEpos} 
        </Tag>
        <Tag 
          color="lime" 
          hidden={!props.checkedKeys.some(checked => checked == 'lib5-0-9')}
        > 
          {'P2573: ' + props.row.dccmaxEpos} 
        </Tag>
        <Tag 
          color="lime" 
          hidden={!props.checkedKeys.some(checked => checked == 'lib5-0-10')}
        > 
          {'P2574: ' + props.row.jerkEpos} 
        </Tag>
        <Tag 
          color="lime" 
          hidden={!props.checkedKeys.some(checked => checked == 'lib5-0-11')}
        > 
          {'P2575: ' + props.row.jerkActiveEpos} 
        </Tag>
        <Tag 
          color="lime" 
          hidden={!props.checkedKeys.some(checked => checked == 'lib5-0-12')}
        > 
          {'P2567: ' + props.row.torquePreCtrl} 
        </Tag>
        <Tag 
          color="lime" 
          hidden={!props.checkedKeys.some(checked => checked == 'lib5-0-13')}
        > 
          {'P2605: ' + props.row.refApproachVel} 
        </Tag>
        <Tag 
          color="lime" 
          hidden={!props.checkedKeys.some(checked => checked == 'lib5-0-14')}
        > 
          {'P2608: ' + props.row.refSearchVel} 
        </Tag>
        <Tag 
          color="lime" 
          hidden={!props.checkedKeys.some(checked => checked == 'lib5-0-15')}
        > 
          {'P29245: ' + modualActiveMap.get(props.row.modualActiveEpos)} 
        </Tag>
        <Tag 
          color="lime" 
          hidden={!props.checkedKeys.some(checked => checked == 'lib5-0-16')}
        > 
          {'P29246: ' + props.row.modualLengthEpos} 
        </Tag>
        <Tag 
          color="lime" 
          hidden={!props.checkedKeys.some(checked => checked == 'lib5-0-17')}
        > 
          {'P2585: ' + props.row.jog1VelEpos} 
        </Tag>
        <Tag 
          color="lime" 
          hidden={!props.checkedKeys.some(checked => checked == 'lib5-0-18')}
        > 
          {'P2586: ' + props.row.jog2VelEpos} 
        </Tag>
        <Tag 
          color="lime" 
          hidden={!props.checkedKeys.some(checked => checked == 'lib5-0-19')}
        > 
          {'p2580: ' + props.row.softLimitPositive} 
        </Tag>
        <Tag 
          color="lime" 
          hidden={!props.checkedKeys.some(checked => checked == 'lib5-0-20')}
        > 
          {'p2581: ' + props.row.softLimitNegative} 
        </Tag>
        <Tag 
          color="lime" 
          hidden={!props.checkedKeys.some(checked => checked == 'lib5-0-21')}
        > 
          {'P2599: ' + props.row.refCoordinate} 
        </Tag>
        <Tag 
          color="lime" 
          hidden={!props.checkedKeys.some(checked => checked == 'lib5-0-22')}
        > 
          {'P29151: ' + pzdMap.get(props.row.pzdSend)} 
        </Tag>

        <Tag 
          color="gold" 
          hidden={!props.checkedKeys.some(checked => checked == 'lib5-1-0')}
        > 
          {'P29120/P1460: ' + props.row.kpSpeed} 
        </Tag>
        <Tag 
          color="gold" 
          hidden={!props.checkedKeys.some(checked => checked == 'lib5-1-1')}
        > 
          {'P29121/P1462: ' + props.row.tnSpeed} 
        </Tag>
        <Tag 
          color="gold" 
          hidden={!props.checkedKeys.some(checked => checked == 'lib5-1-2')}
        > 
          {'P1120: ' + props.row.tincSpeed} 
        </Tag>
        <Tag 
          color="gold" 
          hidden={!props.checkedKeys.some(checked => checked == 'lib5-1-3')}
        > 
          {'P1121: ' + props.row.tdecSpeed} 
        </Tag>
        <Tag 
          color="gold" 
          hidden={!props.checkedKeys.some(checked => checked == 'lib5-1-4')}
        > 
          {'P1130: ' + props.row.tstartSpeed} 
        </Tag>
        <Tag 
          color="gold" 
          hidden={!props.checkedKeys.some(checked => checked == 'lib5-1-5')}
        > 
          {'P1131: ' + props.row.tstopSpeed} 
        </Tag>
        <Tag 
          color="gold" 
          hidden={!props.checkedKeys.some(checked => checked == 'lib5-1-5')}
        > 
          {'P1135: ' + props.row.off3TdecSpeed} 
        </Tag>
        <Tag 
          color="gold" 
          hidden={!props.checkedKeys.some(checked => checked == 'lib5-1-6')}
        > 
          {'P1227: ' + props.row.tmonitorSpeed} 
        </Tag>

      </Space>
    </div>

  );
};

const DriveParaCalcSubtitle = forwardRef<unknown, CalcSubtitleProps>(CalcSubtitle);

export default DriveParaCalcSubtitle;